class Promise {
  constructor (executor) {
    // 控制异步执行的状态
    this.pending = "pending"
    // 用来保存异步执行的结果
    this.data = undefined
    
    const resolve = val => {
      if (this.pending === 'pending'){
        this.pending = "fulfilled"
        this.data = val
        console.log(val)
      }
    }
    const reject = val => {
      if (this.pending === 'pending') {
        this.pending = "rejected"
        this.data = val
        console.log(val)
      }
    }

    executor(resolve, reject)
  }
}

module.exports = Promise